<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属分站">
              <a-input v-if="userInfo.userType == 2 || userInfo.userType == 3" disabled v-model="userInfoSite.name"></a-input>
              <a-input v-if="userInfo.userType == 1" placeholder="请输入分站名称" v-model="queryParam.siteName"></a-input>
            </a-form-item>
          </a-col> -->
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户名">
              <a-input placeholder="请输入用户名" v-model="queryParam.userName"></a-input>
            </a-form-item>
          </a-col> -->
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="登录名">
              <a-input placeholder="请输入登录名" v-model="queryParam.loginName"></a-input>
            </a-form-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="手机号">
              <a-input placeholder="请输入手机号" v-model="queryParam.mobile"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">

            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="创建时间">
                <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.createDateFrom"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.createDateTo"></j-date>
              </a-form-item>
            </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="状态">
                <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.status" dictCode="member_status"/>
              </a-form-item>
            </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="用户姓名">
                <a-input placeholder="请输入用户姓名" v-model="queryParam.name"></a-input>
              </a-form-item>
            </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="性别">
                <j-dict-select-tag placeholder="请选择性别" v-model="queryParam.sex" dictCode="sex"/>
              </a-form-item>
            </a-col> -->
            <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="来源">
                <j-dict-select-tag placeholder="请选择来源" v-model="queryParam.source" dictCode="member_source"/>
              </a-form-item>
            </a-col> -->
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <!-- <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div> -->

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
    selectedRowKeys.length
  }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table ref="table" size="middle" :scroll="{ x: true }" rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="ipagination" :loading="loading" :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap" @change="handleTableChange">
        <span slot="isVip" slot-scope="text, record">
          <a-popconfirm :title="ifViptitle[text].popconfirmTitle" @confirm="() => handleStatusChange(record)">
            <a-tag class="mouse-hand" :color="ifViptitle[text].color">{{ ifViptitle[text].text }}</a-tag>
          </a-popconfirm>
        </span>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
        </span>

      </a-table>
    </div>

    <member-modal ref="modalForm" @ok="modalFormOk"></member-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import MemberModal from './modules/MemberModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import { upDownAction } from '@/api/manage'
import { mapGetters } from 'vuex'
import store from '@/store'

import { putAction } from '../../api/manage'

export default {
  name: 'MemberList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    MemberModal
  },
  data() {
    return {
      description: '会员信息管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '登录名',
          align: "center",
          dataIndex: 'loginName'
        },
        // {
        //   title: '图标',
        //   align: 'left',
        //   dataIndex: 'avatar',
        //   scopedSlots: {
        //     customRender: 'imgSlot'
        //   },
        //   customRender: (text) => {
        //     return <img src={text} alt="avatar" style="max-width: 100px;" />;
        //   }
        // },
        {
          title: '昵称',
          align: "center",
          dataIndex: 'nickName'
        },
        {
          title: '手机号',
          align: "center",
          dataIndex: 'mobile'
        },
        {
          title: '是否会员',
          align: "center",
          dataIndex: 'isVip',
          scopedSlots: { customRender: 'isVip' },
        },
        // {
        //   title: '状态',
        //   align: "center",
        //   dataIndex: 'status',
        //   scopedSlots: { customRender: 'status' },
        // },
        {
          title: '创建日期',
          align: "center",
          dataIndex: 'createTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",

          scopedSlots: { customRender: 'action' }

        },
      ],
      url: {
        list: "/member/list",
        delete: "/member/delete",
        deleteBatch: "/member/deleteBatch",
        statusChange: "/shopPromo/statusChange",
        ifVip: '/api/member/modifyMemberVipStatus/'
      },
      dictOptions: {},
      ifViptitle: {
        1: {
          color: "green",
          text: "会员",
          popconfirmTitle: "确定关闭会员吗?"
        }, 0: {
          color: "pink",
          text: "非会员",
          popconfirmTitle: "确定成会员吗?"
        }
      },
      memberServeData: {
        1: {
          color: "pink",
          text: "冻结",
          popconfirmTitle: "确定恢复吗?"
        }, 0: {
          color: "green",
          text: "正常",
          popconfirmTitle: "确定冻结吗?"
        }
      },
    }
  },
  created() {
    console.log("当前登录用户：", store.getters.userInfo);
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
    ...mapGetters(["permissionData", "userInfo", "userInfoSite"]),
  },
  methods: {
    initDictConfig() {
    },
    handleStatusChange(id) {
      let a = null
      if (id.isVip == '0') {
        a = '1'
      } else {
        a = '0'
      }
      let that = this;
      that.loading = true;
      putAction(this.url.ifVip + id.id + '/' + a).then(res => {
        if (res.success) {
          //重新计算分页问题
          that.reCalculatePage(that.selectedRowKeys.length)
          that.$message.success(res.result);
          that.loadData();
          that.onClearSelected();
        } else {
          that.$message.warning(res.result);
        }
      }).finally(() => {
        that.loading = false;
      });
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>